package com.huahai.service.impl;

import com.huahai.entity.Product;
import com.huahai.service.IProductService;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * Feign调用异常处理逻辑，拿到异常对象
 *  Load balancer does not have available server for client: service-product
 */
@Component
public class ProductFallbackFactory implements FallbackFactory<IProductService> {
    public IProductService create(final Throwable throwable) {
        return new IProductService() {
            public Product findById(Integer pid) {
                System.out.println(throwable);
                Product product = new Product();
                product.setPid(-100);
                return product;
            }
        };
    }
}
